// 保存菜单列表
const menuList = [];
// 保存路由列表
const routeList = [];
// 定义生成菜单的方法
const createMenu = (md,mv,ml,group) => {
    const path = `/${md}${mv}`;
    let d = {module:md,label:ml,value:path}
    if(group){
        d.group = group;
    }
    menuList.push(d)
}
// 定义生成路由的方法
const createRoute = (md,mv,p,fp = 'components') => {
    const path = `/${md}${mv}`;
    const name = `${md}${mv.replace(/-(\w)/g,'_$1')}`
    const cp = import(`../${fp}/${p.replace('./','')}`)
    routeList.push({
        path,
        name,
        component:() => cp
    })
}
// 获取文件信息数据 然后依据信息生成路由和菜单
const getRouterMenu = (com,fp) => {
    com.keys().forEach(path => {
        const ps = path.split('/')
        const l = ps.length;
        const m = ps[1]
        const f = ps[l - 1].replace(/(.vue|.md|.js)/g,'')
        let e = ''
        let g = ''
        if(l > 3){
            g = ps[2]
            for(let i = 2;i<l-1;i++){
                e += '-' + ps[i]
            }
        }
        createMenu(m,e,f,g)
        createRoute(m,e,path,fp);
    })
}
let coms = []
// 定义需要扫描的文件夹和相关规则
const c0 = require.context('@/components/', true, /.*.md$/i)
const c1 = require.context('@/views/', true, /.*.vue$/i)
//const c2 = require.context('@/docs/', true, /.*.md$/i)
// 保存到数组中
coms.push([c0,'components'])
coms.push([c1,'views'])
// coms.push([c2,'docs'])
// 遍历列表 并生成 路由和菜单
coms.forEach((s) => {
    getRouterMenu(s[0],s[1])
})
// 导出数据
export const menus = menuList;
export const routes = routeList;
